import 'package:flutter/material.dart';
import 'package:lib_core/const/net_cst.dart';
import 'package:lib_core/lib_core.dart';

import 'sheet/item_sheet.dart';

class EnvWidget extends StatefulWidget {
  const EnvWidget({super.key});

  @override
  State<EnvWidget> createState() => _EnvWidgetState();
}

class _EnvWidgetState extends State<EnvWidget> {
  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: 0.5,
      child: Align(
        alignment: Alignment.centerRight,
        child: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: _showEnvItems,
          child: Container(
            width: 25,
            decoration: const BoxDecoration(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(4),
                    bottomLeft: Radius.circular(4)),
                color: Color(0xFFBEBEBE)),
            padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 5),
            child: Text(
              NetCst().env.label,
              style: const TextStyle(
                  fontSize: 14,
                  color: Colors.black,
                  fontWeight: FontWeight.normal,
                  decoration: TextDecoration.none),
            ),
          ),
        ),
      ),
    );
  }

  void _showEnvItems() {
    Get.bottomSheet(ItemSheet.withCancel(
      items: [
        SheetItem(value: Env.uat, text: Env.uat.label),
        SheetItem(value: Env.product, text: Env.product.label),
      ],
      onItemSelected: (item) {
        /*_authImpl.logout(() {
            BoostNavigator.instance.popUntil(route: 'main');
          });*/
        NetCst().switchEnv(item.value);
        setState(() {});
      },
      onCancel: () => Get.back(),
    ));
  }
}
